import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

# 股票0 -> 股票stock_day_change.shape[0]


# stock_day_change = np.load('./gen/stock_day_change.npy')
# print(stock_day_change.shape)
#
# # 从2017-1-1向上时间递进，单位freq='1d'即1天
# days = pd.date_range('2017-1-1',
#                      periods=stock_day_change.shape[1], freq='1d')
# # 股票0 -> 股票stock_day_change.shape[0]
# stock_symbols = ['股票 ' + str(x) for x in
#                  range(stock_day_change.shape[0])]
#
#
# df = pd.DataFrame(stock_day_change, index=stock_symbols, columns=days)
# df = df.T
#
# df_20 = df.resample('21D').mean()
# print(df_20.shape)
#
# df_stock0 = df['股票 0']
#
# print(type(df_stock0))
#
# df_stock0.cumsum().plot()

# tsla
from abupy import ABuSymbolPd

tsla_df = ABuSymbolPd.make_kl_df('usTSLA',  n_folds=2, start=None, end='2016-07-26')
print(tsla_df.tail())

#tsla_df[['close', 'volume']].plot(subplots=True, style=['r', 'g'], grid=True)


tsla_df.info()
tsla_df.p_change.hist(bins=80)

cats = pd.qcut(np.abs(tsla_df.p_change), 10)
print(cats.value_counts())
plt.show()